<?
class formatter{
	public function __construct(){
	}
	
	static function number($value){
		#print("<p>LALLA: $value</p>");
		$value=preg_replace("/[^\\d\\.]/i","",$value);
		#print("<p>LALLA: $value</p>");
		return($value);
	}
	
	static function currency($value,$dp=2,$thousands_sep=",",$curr_symbol="$"){
		$value=preg_replace("/[^\\d\\.]/i","",$value);
		if(!is_numeric($value)){
			$value=0;
		}
		$value=$curr_symbol.number_format($value,$dp,".",$thousands_sep);
		return($value);
	}
	
	static function cmsUserData($data=""){
		$result=$data;
		$result=str_replace("\n","<br>",$result);
		return($result);
	}
	
	static function auDateToUniversal($date=NULL,$strtotime=true,$nullIfEmpty=true){
		$result=$date;
		if($date!==NULL&&strlen($date)>0){
			$ar=preg_split("/[\/\.\-\s]/",$date);
			if(count($ar)>2){
				$result=$ar[2]."-".$ar[1]."-".$ar[0];
				if(count($ar)>3){
					$result.=" ".$ar[3];
				}
				if($strtotime){
					$result=strtotime($result);
				}
			}
		}elseif($nullIfEmpty){
			$result=NULL;
		}
		return($result);
	}
	
	/*
		Calculates and Formats the difference in dates.
		Formatting
			NULL/Empty: full output (i.e. 2 years, 3 months, 1 week, 2 days).
			n=Nearest, rounded (i.e. if its 2 years and 5 days, result=2 years)
			c=compact (i.e. 1Y2M3W2D4H)
	*/
	static function dateDifference($date1=NULL,$date2=NULL,$format=NULL){
		$result=0;
		$diff=0;
		$tmp=0;
		$date1=($date1===NULL)?time():$date1;
		$date2=($date2===NULL)?time():$date2;
		if($date2<$date1){
			$tmp=$date2;
			$date2=$date1;
			$date1=$tmp;
		}
		$diff=$date2-$date1;
		
		return($result);
	}
	
	/*
		Returns a JavaScript formatted string
	*/
	static function jsText($content=""){
		return(preg_replace('`[\r\n]`','\n',addslashes($content)));
	}
};
?>